package com.yuexunit.operationman.nbsy.module.Catheter.ui;

import android.content.Context;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.bumptech.glide.Glide;

import com.yuexunit.operationman.nbsy.R;
import com.yuexunit.operationman.nbsy.base.BaseKJActivity;
import com.yuexunit.operationman.nbsy.base.SubmitBean;
import com.yuexunit.operationman.nbsy.config.AppConfig;
import com.yuexunit.operationman.nbsy.module.Catheter.bean.CatheterBean;
import com.yuexunit.operationman.nbsy.module.Catheter.model.impl.CatheterModel;
import com.yuexunit.operationman.nbsy.module.Catheter.presenter.ICatheterPresenter;
import com.yuexunit.operationman.nbsy.module.Catheter.presenter.impl.CatheterPresenter;
import com.yuexunit.operationman.nbsy.module.Catheter.ui.view.ICatheterView;
import com.yuexunit.operationman.nbsy.module.SafeOperation.bean.SignBean;
import com.yuexunit.operationman.nbsy.module.SafeOperation.model.impl.SafeOperationSignModel;
import com.yuexunit.operationman.nbsy.module.SafeOperation.presenter.ISafeOperationSignPresenter;
import com.yuexunit.operationman.nbsy.module.SafeOperation.presenter.impl.SafeOperationSignPresenter;
import com.yuexunit.operationman.nbsy.module.SafeOperation.ui.view.ISafeOperationSignView;
import com.yuexunit.operationman.nbsy.widget.ActionSheetDialog;
import com.yuexunit.operationman.nbsy.widget.ClickDialog;
import com.yuexunit.operationman.nbsy.widget.LoadingDialog;
import com.yuexunit.operationman.nbsy.widget.LoginDialog;

import org.kymjs.kjframe.ui.ViewInject;
import org.kymjs.kjframe.utils.PreferenceHelper;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by chenss on 2017/12/27 0027.
 */

public class Act_Catheter_Use extends BaseKJActivity implements ICatheterView, ISafeOperationSignView {

    @Bind(R.id.tv_patient_name)
    TextView tvPatientName;
    @Bind(R.id.tv_patient_sex)
    TextView tvPatientSex;
    @Bind(R.id.tv_patient_visitno)
    TextView tvPatientVisitno;
    @Bind(R.id.tv_patient_disease)
    TextView tvPatientDisease;
    @Bind(R.id.radio_01_01)
    RadioButton radio0101;
    @Bind(R.id.radio_01_02)
    RadioButton radio0102;
    @Bind(R.id.radio_01_03)
    RadioButton radio0103;
    @Bind(R.id.radio_01_04)
    RadioButton radio0104;
    @Bind(R.id.radio_02_01)
    CheckBox radio0201;
    @Bind(R.id.radio_02_02)
    CheckBox radio0202;
    @Bind(R.id.radio_02_03)
    CheckBox radio0203;
    @Bind(R.id.radio_02_04)
    CheckBox radio0204;
    @Bind(R.id.radio_02_05)
    CheckBox radio0205;
    @Bind(R.id.radio_02_06)
    CheckBox radio0206;
    @Bind(R.id.radio_02_07)
    CheckBox radio0207;
    @Bind(R.id.radio_02_08)
    CheckBox radio0208;
    @Bind(R.id.radio_02_other_txt)
    EditText radio02OtherTxt;
    @Bind(R.id.iv_radio_02_other)
    LinearLayout ivRadio02Other;
    @Bind(R.id.radio_03_01)
    RadioButton radio0301;
    @Bind(R.id.radio_03_02)
    RadioButton radio0302;
    @Bind(R.id.radio_03_03)
    RadioButton radio0303;
    @Bind(R.id.radio_03_04)
    CheckBox radio0304;
    @Bind(R.id.radio_03_05)
    CheckBox radio0305;
    @Bind(R.id.radio_04_01)
    RadioButton radio0401;
    @Bind(R.id.radio_04_02)
    RadioButton radio0402;
    @Bind(R.id.radio_04_03)
    RadioButton radio0403;
    @Bind(R.id.radio_05_01)
    RadioButton radio0501;
    @Bind(R.id.radio_05_02)
    RadioButton radio0502;
    @Bind(R.id.radio_05_03)
    RadioButton radio0503;
    @Bind(R.id.radio_06_01)
    RadioButton radio0601;
    @Bind(R.id.radio_06_02)
    RadioButton radio0602;
    @Bind(R.id.radio_06_03)
    RadioButton radio0603;
    @Bind(R.id.radio_06_04)
    RadioButton radio0604;
    @Bind(R.id.radio_06_05)
    RadioButton radio0605;
    @Bind(R.id.radio_07_01)
    RadioButton radio0701;
    @Bind(R.id.radio_07_02)
    RadioButton radio0702;
    @Bind(R.id.radio_07_03)
    RadioButton radio0703;
    @Bind(R.id.radio_08_01)
    RadioButton radio0801;
    @Bind(R.id.radio_08_02)
    RadioButton radio0802;
    @Bind(R.id.radio_08_03)
    RadioButton radio0803;
    @Bind(R.id.radio_09_01)
    RadioButton radio0901;
    @Bind(R.id.radio_09_02)
    RadioButton radio0902;
    @Bind(R.id.radio_09_03)
    RadioButton radio0903;
    @Bind(R.id.radio_09_04)
    RadioButton radio0904;
    @Bind(R.id.radio_09_05)
    RadioButton radio0905;
    @Bind(R.id.radio_10_01)
    RadioButton radio1001;
    @Bind(R.id.radio_10_02)
    RadioButton radio1002;
    @Bind(R.id.radio_10_03)
    RadioButton radio1003;
    @Bind(R.id.radio_11_01)
    RadioButton radio1101;
    @Bind(R.id.radio_11_02)
    RadioButton radio1102;
    @Bind(R.id.radio_11_03)
    RadioButton radio1103;

    //签名
    @Bind(R.id.img_sign_visit)
    ImageView imgSignVisit;
    @Bind(R.id.btn_sign_visit)
    TextView btnSignVisit;
    @Bind(R.id.tv_sign_visit_time)
    TextView tvSignVisitTime;
    @Bind(R.id.tv_sign_visit_name)
    TextView tvSignVisitName;

    LoadingDialog loadingDialog;
    ICatheterPresenter presenter;

    LoginDialog loginDialog;
    ISafeOperationSignPresenter presenter_sign;

    ClickDialog dialog;

    @Override
    public void setRootView() {
        setContentView(R.layout.act_catheter_use);
        ButterKnife.bind(this);
    }

    @Override
    public void initData() {
        super.initData();
        loginDialog = new LoginDialog(aty);
        loadingDialog = new LoadingDialog(this);
        presenter = new CatheterPresenter(this, new CatheterModel());
        presenter_sign = new SafeOperationSignPresenter(this, new SafeOperationSignModel());
        setTitle();
        setContent();
    }

    private void setTitle() {
        tvPatientName.setText(AppConfig.CATHETERBEAN.getObject().getCatheter().getPatientName());
        if (AppConfig.CATHETERBEAN.getObject().getCatheter().getPatientSex().equals("1")) {
            tvPatientSex.setText("男");
        } else if (AppConfig.CATHETERBEAN.getObject().getCatheter().getPatientSex().equals("2")) {
            tvPatientSex.setText("女");
        } else {
            tvPatientSex.setText("不详");
        }
        tvPatientVisitno.setText("住院号" + AppConfig.CATHETERBEAN.getObject().getCatheter().getInHospitalNo());
        tvPatientDisease.setText(PreferenceHelper.readString(aty, AppConfig.PATIENT_INFO, AppConfig.PATIENT_DISEASE));
    }

    private void setContent() {
        if (AppConfig.CATHETERBEAN.getObject().getCatheter().getOperatorSign() != null
                && AppConfig.CATHETERBEAN.getObject().getCatheter().getOperatorSign().length() > 0) {
            imgSignVisit.setVisibility(View.VISIBLE);
            btnSignVisit.setVisibility(View.GONE);
            tvSignVisitTime.setVisibility(View.VISIBLE);
            tvSignVisitName.setVisibility(View.VISIBLE);
            Glide.with(aty)
                    .load(AppConfig.CATHETERBEAN.getObject().getCatheter().getOperatorSign())
                    .placeholder(R.color.white)
                    .error(R.color.white)
                    .into(imgSignVisit);
            tvSignVisitTime.setText("签名时间:" + AppConfig.CATHETERBEAN.getObject().getCatheter().getOperationDate());
            tvSignVisitName.setText(AppConfig.CATHETERBEAN.getObject().getCatheter().getOperator());
        }

        for (CatheterBean.ObjectEntity.CatheterItemListEntity p : AppConfig.CATHETERBEAN.getObject().getCatheterItemList()) {
            switch (p.getItemCode()) {
                case "DGLX":
                    if (p.getItemValue().length() > 0) {
                        String[] skin = p.getItemValue().split(";", -1);
                        if (skin[0].equals("1")) {
                            radio0101.setChecked(true);
                        }
                        if (skin[1].equals("1")) {
                            radio0102.setChecked(true);
                        }
                        if (skin[2].equals("1")) {
                            radio0103.setChecked(true);
                        }
                        if (skin[3].equals("1")) {
                            radio0104.setChecked(true);
                        }
                    }
                    break;
                case "DNMD":
                    if (p.getItemValue().length() > 0) {
                        String[] skin = p.getItemValue().split(";", -1);
                        if (skin[0].equals("1")) {
                            radio0201.setChecked(true);
                        }
                        if (skin[1].equals("1")) {
                            radio0202.setChecked(true);
                        }
                        if (skin[2].equals("1")) {
                            radio0203.setChecked(true);
                        }
                        if (skin[3].equals("1")) {
                            radio0204.setChecked(true);
                        }
                        if (skin[4].equals("1")) {
                            radio0205.setChecked(true);
                        }
                        if (skin[5].equals("1")) {
                            radio0206.setChecked(true);
                        }
                        if (skin[6].equals("1")) {
                            radio0207.setChecked(true);
                        }
                        if (skin[7].equals("1")) {
                            radio0208.setChecked(true);
                            ivRadio02Other.setVisibility(View.VISIBLE);
                            radio02OtherTxt.setText(skin[8]);
                        }
                    }
                    break;
                case "item1":
                    if (p.getItemValue().length() > 0) {
                        String[] skin = p.getItemValue().split(";", -1);
                        if (skin[0].equals("1")) {
                            radio0301.setChecked(true);
                        }
                        if (skin[1].equals("1")) {
                            radio0302.setChecked(true);
                        }
                        if (skin[2].equals("1")) {
                            radio0303.setChecked(true);
                        }
                        if (skin[3].equals("1")) {
                            radio0304.setChecked(true);
                        }
                        if (skin[4].equals("1")) {
                            radio0305.setChecked(true);
                        }
                    }
                    break;
                case "item2":
                    if (p.getItemValue().length() > 0) {
                        String[] skin = p.getItemValue().split(";", -1);
                        if (skin[0].equals("1")) {
                            radio0401.setChecked(true);
                        }
                        if (skin[1].equals("1")) {
                            radio0402.setChecked(true);
                        }
                        if (skin[2].equals("1")) {
                            radio0403.setChecked(true);
                        }
                    }
                    break;
                case "item3":
                    if (p.getItemValue().length() > 0) {
                        String[] skin = p.getItemValue().split(";", -1);
                        if (skin[0].equals("1")) {
                            radio0501.setChecked(true);
                        }
                        if (skin[1].equals("1")) {
                            radio0502.setChecked(true);
                        }
                        if (skin[2].equals("1")) {
                            radio0503.setChecked(true);
                        }
                    }
                    break;
                case "item4":
                    if (p.getItemValue().length() > 0) {
                        String[] skin = p.getItemValue().split(";", -1);
                        if (skin[0].equals("1")) {
                            radio0601.setChecked(true);
                        }
                        if (skin[1].equals("1")) {
                            radio0602.setChecked(true);
                        }
                        if (skin[2].equals("1")) {
                            radio0603.setChecked(true);
                        }
                        if (skin[3].equals("1")) {
                            radio0604.setChecked(true);
                        }
                        if (skin[4].equals("1")) {
                            radio0605.setChecked(true);
                        }
                    }
                    break;
                case "item5":
                    if (p.getItemValue().length() > 0) {
                        String[] skin = p.getItemValue().split(";", -1);
                        if (skin[0].equals("1")) {
                            radio0701.setChecked(true);
                        }
                        if (skin[1].equals("1")) {
                            radio0702.setChecked(true);
                        }
                        if (skin[2].equals("1")) {
                            radio0703.setChecked(true);
                        }
                    }
                    break;
                case "item6":
                    if (p.getItemValue().length() > 0) {
                        String[] skin = p.getItemValue().split(";", -1);
                        if (skin[0].equals("1")) {
                            radio0801.setChecked(true);
                        }
                        if (skin[1].equals("1")) {
                            radio0802.setChecked(true);
                        }
                        if (skin[2].equals("1")) {
                            radio0803.setChecked(true);
                        }
                    }
                    break;
                case "item7":
                    if (p.getItemValue().length() > 0) {
                        String[] skin = p.getItemValue().split(";", -1);
                        if (skin[0].equals("1")) {
                            radio0901.setChecked(true);
                        }
                        if (skin[1].equals("1")) {
                            radio0902.setChecked(true);
                        }
                        if (skin[2].equals("1")) {
                            radio0903.setChecked(true);
                        }
                        if (skin[3].equals("1")) {
                            radio0904.setChecked(true);
                        }
                        if (skin[4].equals("1")) {
                            radio0905.setChecked(true);
                        }
                    }
                    break;
                case "item8":
                    if (p.getItemValue().length() > 0) {
                        String[] skin = p.getItemValue().split(";", -1);
                        if (skin[0].equals("1")) {
                            radio1001.setChecked(true);
                        }
                        if (skin[1].equals("1")) {
                            radio1002.setChecked(true);
                        }
                        if (skin[2].equals("1")) {
                            radio1003.setChecked(true);
                        }
                    }
                    break;
                case "item9":
                    if (p.getItemValue().length() > 0) {
                        String[] skin = p.getItemValue().split(";", -1);
                        if (skin[0].equals("1")) {
                            radio1101.setChecked(true);
                        }
                        if (skin[1].equals("1")) {
                            radio1102.setChecked(true);
                        }
                        if (skin[2].equals("1")) {
                            radio1103.setChecked(true);
                        }
                    }
                    break;
            }
        }
    }

    @OnClick({R.id.titlebar_docadvice_img_back, R.id.radio_02_08, R.id.sure, R.id.btn_sign_visit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.titlebar_docadvice_img_back:
                finish();
                break;
            case R.id.radio_02_08:
                if (radio0208.isChecked()) {
                    ivRadio02Other.setVisibility(View.VISIBLE);
                } else {
                    ivRadio02Other.setVisibility(View.GONE);
                }
                break;
            case R.id.sure:
                if (AppConfig.CATHETERBEAN.getObject().getCatheter().getOperator() != null) {
                    insertContent();
                } else {
                    dialog = new ClickDialog(aty).builder().setTxt("存在未签名,是否提交？");
                    dialog.isCancleBack(true);
                    dialog.setCallBack(new ClickDialog.ICallBack() {
                        @Override
                        public void callback(Bundle bundle) {
                            if (bundle.getInt("data") == 0) {
                                insertContent();
                            } else if (bundle.getInt("data") == 1) {
                                dialog.dismiss();
                            }

                        }
                    });
                    dialog.show();
                }
                break;
            case R.id.btn_sign_visit:
                showTypeDialog();
                break;
        }
    }

    private void showTypeDialog() {
        ActionSheetDialog actionSheetDialog;
        actionSheetDialog = new ActionSheetDialog(this).builder()
                .setCancelable(true)
                .setCanceledOnTouchOutside(true);
        actionSheetDialog.addSheetItem("HIS签名", ActionSheetDialog.SheetItemColor.Blue,
                new ActionSheetDialog.OnSheetItemClickListener() {
                    @Override
                    public void onClick(int which) {
                        loginDialog.builder();
                        loginDialog.show();
                        loginDialog.setCallBack(new LoginDialog.ICallBack() {
                            @Override
                            public void callback(Bundle bundle) {
                                Map<String, String> params = new HashMap<>();
                                params.put("jobNum", bundle.getString("person_num"));
                                params.put("loginPwd", bundle.getString("person_psw"));
                                presenter_sign.getSignInfo(params);
                            }
                        });
                    }
                });
        actionSheetDialog.addSheetItem("虹膜签名(暂不可用)", ActionSheetDialog.SheetItemColor.Blue,
                new ActionSheetDialog.OnSheetItemClickListener() {
                    @Override
                    public void onClick(int which) {

                    }
                });
        actionSheetDialog.show();
    }

    @Override
    public void getSignInfo(SignBean signBean) {
        loginDialog.dismiss();
        if (signBean.getCode() == 200) {
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", java.util.Locale.getDefault());
            Date curDate = new Date(System.currentTimeMillis());//获取当前时间
            String str = formatter.format(curDate);
            imgSignVisit.setVisibility(View.VISIBLE);
            Glide.with(this)
                    .load(signBean.getObject().getSignPicture())
                    .placeholder(R.color.white)
                    .error(R.color.white)
                    .into(imgSignVisit);
            btnSignVisit.setVisibility(View.GONE);
            tvSignVisitTime.setVisibility(View.VISIBLE);
            tvSignVisitTime.setText("签名时间:" + str);
            tvSignVisitName.setVisibility(View.VISIBLE);
            tvSignVisitName.setText(signBean.getObject().getDoctorName());

            AppConfig.CATHETERBEAN.getObject().getCatheter().setOperator(signBean.getObject().getDoctorName());
            AppConfig.CATHETERBEAN.getObject().getCatheter().setOperatorSign(signBean.getObject().getSignPicture());
            AppConfig.CATHETERBEAN.getObject().getCatheter().setOperationDate(str);
        } else {
            ViewInject.toast(signBean.getDesc());
        }
    }

    private void insertContent() {
        for (int i = 0; i < AppConfig.CATHETERBEAN.getObject().getCatheterItemList().size(); i++) {
            String value = "";
            switch (AppConfig.CATHETERBEAN.getObject().getCatheterItemList().get(i).getItemCode()) {
                case "DGLX":
                    if (radio0101.isChecked()) {
                        AppConfig.CATHETERBEAN.getObject().getCatheterItemList().get(i).setItemValue("1;;;");
                    }
                    if (radio0102.isChecked()) {
                        AppConfig.CATHETERBEAN.getObject().getCatheterItemList().get(i).setItemValue(";1;;");
                    }
                    if (radio0103.isChecked()) {
                        AppConfig.CATHETERBEAN.getObject().getCatheterItemList().get(i).setItemValue(";;1;");
                    }
                    if (radio0104.isChecked()) {
                        AppConfig.CATHETERBEAN.getObject().getCatheterItemList().get(i).setItemValue(";;;1");
                    }
                    break;
                case "DNMD":
                    if (radio0201.isChecked()) {
                        value += "1;";
                    } else {
                        value += ";";
                    }

                    if (radio0202.isChecked()) {
                        value += "1;";
                    } else {
                        value += ";";
                    }

                    if (radio0203.isChecked()) {
                        value += "1;";
                    } else {
                        value += ";";
                    }

                    if (radio0204.isChecked()) {
                        value += "1;";
                    } else {
                        value += ";";
                    }

                    if (radio0205.isChecked()) {
                        value += "1;";
                    } else {
                        value += ";";
                    }

                    if (radio0206.isChecked()) {
                        value += "1;";
                    } else {
                        value += ";";
                    }

                    if (radio0207.isChecked()) {
                        value += "1;";
                    } else {
                        value += ";";
                    }

                    if (radio0208.isChecked()) {
                        value += "1;" + radio02OtherTxt.getText().toString();
                    } else {
                        value += ";";
                    }
                    AppConfig.CATHETERBEAN.getObject().getCatheterItemList().get(i).setItemValue(value);
                    break;
                case "item1":
                    if (radio0301.isChecked()) {
                        value += "1;";
                    } else {
                        value += ";";
                    }
                    if (radio0302.isChecked()) {
                        value += "1;";
                    } else {
                        value += ";";
                    }
                    if (radio0303.isChecked()) {
                        value += "1;";
                    } else {
                        value += ";";
                    }
                    if (radio0304.isChecked()) {
                        value += "1;";
                    } else {
                        value += ";";
                    }
                    if (radio0305.isChecked()) {
                        value += "1";
                    } else {
                        value += "";
                    }
                    AppConfig.CATHETERBEAN.getObject().getCatheterItemList().get(i).setItemValue(value);
                    break;
                case "item2":
                    if (radio0401.isChecked()) {
                        AppConfig.CATHETERBEAN.getObject().getCatheterItemList().get(i).setItemValue("1;;");
                    }
                    if (radio0402.isChecked()) {
                        AppConfig.CATHETERBEAN.getObject().getCatheterItemList().get(i).setItemValue(";1;");
                    }
                    if (radio0403.isChecked()) {
                        AppConfig.CATHETERBEAN.getObject().getCatheterItemList().get(i).setItemValue(";;1");
                    }
                    break;
                case "item3":
                    if (radio0501.isChecked()) {
                        AppConfig.CATHETERBEAN.getObject().getCatheterItemList().get(i).setItemValue("1;;");
                    }
                    if (radio0502.isChecked()) {
                        AppConfig.CATHETERBEAN.getObject().getCatheterItemList().get(i).setItemValue(";1;");
                    }
                    if (radio0503.isChecked()) {
                        AppConfig.CATHETERBEAN.getObject().getCatheterItemList().get(i).setItemValue(";;1");
                    }
                    break;
                case "item4":
                    if (radio0601.isChecked()) {
                        value += "1;";
                    } else {
                        value += ";";
                    }
                    if (radio0602.isChecked()) {
                        value += "1;";
                    } else {
                        value += ";";
                    }
                    if (radio0603.isChecked()) {
                        value += "1;";
                    } else {
                        value += ";";
                    }
                    if (radio0604.isChecked()) {
                        value += "1;";
                    } else {
                        value += ";";
                    }
                    if (radio0605.isChecked()) {
                        value += "1";
                    } else {
                        value += "";
                    }
                    AppConfig.CATHETERBEAN.getObject().getCatheterItemList().get(i).setItemValue(value);
                    break;
                case "item5":
                    if (radio0701.isChecked()) {
                        AppConfig.CATHETERBEAN.getObject().getCatheterItemList().get(i).setItemValue("1;;");
                    }
                    if (radio0702.isChecked()) {
                        AppConfig.CATHETERBEAN.getObject().getCatheterItemList().get(i).setItemValue(";1;");
                    }
                    if (radio0703.isChecked()) {
                        AppConfig.CATHETERBEAN.getObject().getCatheterItemList().get(i).setItemValue(";;1");
                    }
                    break;
                case "item6":
                    if (radio0801.isChecked()) {
                        AppConfig.CATHETERBEAN.getObject().getCatheterItemList().get(i).setItemValue("1;;");
                    }
                    if (radio0802.isChecked()) {
                        AppConfig.CATHETERBEAN.getObject().getCatheterItemList().get(i).setItemValue(";1;");
                    }
                    if (radio0803.isChecked()) {
                        AppConfig.CATHETERBEAN.getObject().getCatheterItemList().get(i).setItemValue(";;1");
                    }
                    break;
                case "item7":
                    if (radio0901.isChecked()) {
                        value += "1;";
                    } else {
                        value += ";";
                    }
                    if (radio0902.isChecked()) {
                        value += "1;";
                    } else {
                        value += ";";
                    }
                    if (radio0903.isChecked()) {
                        value += "1;";
                    } else {
                        value += ";";
                    }
                    if (radio0904.isChecked()) {
                        value += "1;";
                    } else {
                        value += ";";
                    }
                    if (radio0905.isChecked()) {
                        value += "1";
                    } else {
                        value += "";
                    }
                    AppConfig.CATHETERBEAN.getObject().getCatheterItemList().get(i).setItemValue(value);
                    break;
                case "item8":
                    if (radio1001.isChecked()) {
                        AppConfig.CATHETERBEAN.getObject().getCatheterItemList().get(i).setItemValue("1;;");
                    }
                    if (radio1002.isChecked()) {
                        AppConfig.CATHETERBEAN.getObject().getCatheterItemList().get(i).setItemValue(";1;");
                    }
                    if (radio1003.isChecked()) {
                        AppConfig.CATHETERBEAN.getObject().getCatheterItemList().get(i).setItemValue(";;1");
                    }
                    break;
                case "item9":
                    if (radio1101.isChecked()) {
                        AppConfig.CATHETERBEAN.getObject().getCatheterItemList().get(i).setItemValue("1;;");
                    }
                    if (radio1102.isChecked()) {
                        AppConfig.CATHETERBEAN.getObject().getCatheterItemList().get(i).setItemValue(";1;");
                    }
                    if (radio1103.isChecked()) {
                        AppConfig.CATHETERBEAN.getObject().getCatheterItemList().get(i).setItemValue(";;1");
                    }
                    break;
            }
        }
        if (AppConfig.CATHETERBEAN.getObject().getCatheter().getCatheterId() == null) {
            Map<String, String> params = new HashMap<>();
            params.put("operationNo", PreferenceHelper.readString(aty, AppConfig.PATIENT_INFO, AppConfig.PATIENT_OPERATION_ID) + "");
            params.put("saveData", JSON.toJSONString(AppConfig.CATHETERBEAN));
            presenter.insertCatheterDate(params);
        } else {
            Map<String, String> params = new HashMap<>();
            params.put("accountId", PreferenceHelper.readInt(aty, AppConfig.USER_INFO, AppConfig.USER_ACCOUNT) + "");
            params.put("fullName", PreferenceHelper.readString(aty, AppConfig.USER_INFO, AppConfig.USER_FULLNAME) + "");
            params.put("saveData", JSON.toJSONString(AppConfig.CATHETERBEAN));
            presenter.updateCatheterDate(params);
        }
    }

    @Override
    public void insertCatheterDate(SubmitBean submitBean) {
        if (submitBean.getCode() == 200) {
            ViewInject.toast("保存成功");
            finish();
        } else {
            ViewInject.toast(submitBean.getDesc());
        }
    }

    @Override
    public void updateCatheterDate(SubmitBean submitBean) {
        if (submitBean.getCode() == 200) {
            ViewInject.toast("保存成功");
            finish();
        } else {
            ViewInject.toast(submitBean.getDesc());
        }
    }

    @Override
    public void loadingDialogStatus(int status) {
        switch (status) {
            case AppConfig.SHOW_DIALOG:
                loadingDialog.setCanceledOnTouchOutside(false);
                loadingDialog.show();
                break;
            case AppConfig.DISMISS_DIALOG:
                loadingDialog.dismiss();
                break;

        }
    }


    /**
     * 通过dispatchTouchEvent每次ACTION_DOWN事件中动态判断非EditText本身区域的点击事件，然后在事件中进行屏蔽。然后当点击不是EditText时候，进行隐藏键盘操作
     *
     * @param ev
     * @return
     */

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        if (ev.getAction() == MotionEvent.ACTION_DOWN) {
            View v = getCurrentFocus();
            if (isShouldHideInput(v, ev)) {

                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                if (imm != null) {
                    imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
                }
            }
            return super.dispatchTouchEvent(ev);
        }
        if (getWindow().superDispatchTouchEvent(ev)) {
            return true;
        }
        return onTouchEvent(ev);
    }

    public boolean isShouldHideInput(View v, MotionEvent event) {

        if (v != null && (v instanceof EditText)) {
            int[] leftTop = {0, 0};
            //获取输入框当前的location位置
            v.getLocationInWindow(leftTop);
            int left = leftTop[0];
            int top = leftTop[1];
            int bottom = top + v.getHeight();
            int right = left + v.getWidth();
            if (event.getX() > left && event.getX() < right
                    && event.getY() > top && event.getY() < bottom) {
                // 点击的是输入框区域，保留点击EditText的事件\
                return false;
            } else {
                return true;
            }
        }
        return false;
    }
}
